<div class="layui-fluid">
    <div class="layui-card">
        <!--        <div class="layui-form layui-card-header layuiadmin-card-header-auto">-->
        <!--            <div class="layui-form-item">-->
        <!--                <div class="layui-inline">-->
        <!--                    <label class="layui-form-label">店铺名称</label>-->
        <!--                    <div class="layui-input-block">-->
        <!--                        <input type="text" name="title" id="title" placeholder="请输入店铺名称" autocomplete="off"-->
        <!--                               class="layui-input">-->
        <!--                    </div>-->
        <!--                </div>-->

        <!--                <div class="layui-inline">-->
        <!--                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">-->
        <!--                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
        <!--                    </button>-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->
        <div class="layui-card-body">
            <!--            <div style="padding-bottom: 10px;">-->
            <!--            <button class="layui-btn layuiadmin-btn-admin layui-btn-sm" title="刷新" data-type="refresh"><i-->
            <!--                    class="layui-icon layui-icon-refresh-3"></i>-->
            <!--            </button>-->
            <!--            <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('flow/add')?$auth->check('flow/add'):'hide'}"-->
            <!--                    title="添加" data-type="add"><i-->
            <!--                    class="layui-icon layui-icon-add-1"></i>添加-->
            <!--            </button>-->
            <!--            <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('flow/del')?$auth->check('flow/del'):'hide'}"-->
            <!--                    title="删除" data-type="batchdel"><i-->
            <!--                    class="layui-icon layui-icon-delete"></i>删除-->
            <!--            </button>-->
            <!--            &lt;!&ndash;                <button class="layui-btn layuiadmin-btn-admin layui-btn-sm {$auth->check('flow/export')?$auth->check('flow/export'):'hide'}"&ndash;&gt;-->
            <!--            &lt;!&ndash;                        title="导出" data-type="export"><i&ndash;&gt;-->
            <!--            &lt;!&ndash;                        class="iconfont icon-daochu"></i>导出&ndash;&gt;-->
            <!--            &lt;!&ndash;                </button>&ndash;&gt;-->
            <!--        </div>-->
            <table class="layui-table" id="LAY-user-back-manage" lay-filter="LAY-user-back-manage">
                <thead>
                <tr>
                    <th>审批类别</th>
                    <th>审批类型</th>
                    <th>申请人</th>
                    <th>所属部门</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name='list' id='k'}
                <tr>
                    <td>{$k.type_name}</td>
                    <td>{$k.approval_type}</td>
                    <td>{$k.username}</td>
                    <td>{$k.group_name}</td>
                    <td>
                        <!--获取流状态-->
                        {:app\\admin\\controller\\Wf::status($k.status_table)}
                    </td>
                    <td class="td-manage">
                        <div class="btn-group">
                            {if $k.status eq 0 && $k.sh_status eq 1}
                            <a data-id="{$k.id}" data-name="{$k.approval_type}"
                               class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('applies/sh')?$auth->check('applies/sh'):'hide'}"
                               lay-submit lay-filter="sh-submit"><i
                                    class="layui-icon layui-icon-edit"></i>部门审核</a>
                            {elseif $k.status eq 1}
                                {:app\\admin\\controller\\Wf::btn($k.from_id,$k.from_table,$k.status_table)}
                            {else}
                            <a data-id="{$k.id}" data-name="{$k.approval_type}"
                               class="layui-btn layui-btn-normal layui-btn-xs {$auth->check('applies/sh')?$auth->check('applies/sh'):'hide'}"><i
                                    class="layui-icon layui-icon-edit"></i>无权限</a>
                            {/if}
                        </div>
                    </td>
                </tr>
                {/volist}
                </tbody>


            </table>
            <!--            <script type="text/html" id="admin">-->
            <!--              {= d.status_table }-->

            <!--&lt;!&ndash;                {:app\\admin\\controller\\wf::btn('"+d.from_id+"','"+d.from_table+"','"+d.status+"')}&ndash;&gt;-->
            <!--            </script>-->
            <!--&lt;!&ndash;            <script type="text/html" id="status_flow">&ndash;&gt;-->

            <!--&lt;!&ndash;                {:app\\admin\\controller\\wf::status('1')}&ndash;&gt;-->
            <!--&lt;!&ndash;            </script>&ndash;&gt;-->

        </div>
    </div>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    var listUrl = "{:url('administration/approval')}", approval_check = "{:url('flow/approval_check')}",
        checkFlow = "{:url('flow/check_flow')}", sh = "{:url('applies/sh')}",sh_detail ="{:url('applies/sh_detail')}";
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'soulTable'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table, soulTable = layui.soulTable, laytpl = layui.laytpl;


        form.on("submit(sh-submit)", function (res) {
            var param = $.param({'id': $(this).data('id')});
            layer.open({
                type: 2
                , skin: 'layui-layer-molv'
                , title: '审核-' + $(this).data('name')
                , id: 'sh_' + $(this).data('id')
                , content: sh + '?' + param
                , area: ['50%', '50%']
                , maxmin: true
                , btn: ['通过', '拒绝', '取消']
                , yes: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-back-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        //提交 Ajax 成功后，静态更新表格中的数据
                        $.ajax({
                            url: sh,
                            type: "post",
                            typeData: "json",
                            data: field,
                            // beforeSend: function () {
                            //     layer.load(2, {
                            //         shade: [0.6, '#fff'], content: '数据提交中...', success: function (layero) {
                            //             layero.find('.layui-layer-content').css({
                            //                 'padding-top': '6px',
                            //                 'width': '150px',
                            //                 'padding-left': '40px'
                            //             });
                            //             layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                            //                 'width': '150px !important',
                            //                 'background-position': '2px 0 !important'
                            //             });
                            //         }
                            //     });
                            // },
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    location.reload();
                                    layer.closeAll(); //关闭弹层
                                } else {
                                    layer.msg(res.msg, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                },btn2:function (index, layero) {
                   layer.msg("开通中...");
                }
            });
        });
        form.on("submit(sh-check)",function () {
            var param = $.param({'from_id': $(this).data('id'),'from_table':$(this).data('type')});
            layer.open({
                type: 2
                , skin: 'layui-layer-molv'
                , title: '详情'
                , id: 'sh_' + $(this).data('id')
                , content: sh_detail + '?' + param
                , area: ['50%', '50%']
                , maxmin: true


            });
        });

        // table.render({
        //     elem: "#LAY-user-back-manage", url: listUrl
        //     , cellMinWidth: 100
        //     , cols: [
        //         [
        //             {type: "checkbox", fixed: "left"},
        //             {field: "alternative_title", align: "center", title: "审批类型"},
        //             {field: "username", align: "center", title: "申请人"},
        //             {field: "group_name", align: "center", title: "所属部门"},
        //             // {field: "status", align: "center", title: "申请人"},
        //             // {field: "btn", align: "center", title: "所属部门"},
        //             {title: "操作", align: "center", fixed: "right", toolbar: "#admin"},
        //             // {title: "操作", align: "center", fixed: "right", toolbar: "#admin"}
        //          ]]
        //     , done: function (res, curr, count) {
        //
        //     },
        //     response: {
        //         statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
        //     },
        //     parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
        //         return {
        //             "code": res.code,
        //             "count": res.total, //解析数据长度
        //             "data": res.data, //解析数据列表
        //         };
        //
        //     },
        //     text: {
        //         'none': "呀！一条数据都没有？"
        //     },
        //     page: true,
        //     limit: 20,
        // });
        //按钮触发
        table.on("tool(LAY-user-back-manage)", function (e) {
            var param = $.param({'id': e.data.id});
            if ("edit" === e.event) {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '编辑'
                    , content: edit + '?' + param
                    , area: ['80%', '80%']
                    , maxmin: true
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url: edit + '?' + param,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    console.log(res);
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            } else if ("del" === e.event) {
                var params = $.param({'ids': e.data.id});
                layer.confirm("确定删除吗？", function (t) {
                    $.ajax({
                        url: deleteUrl + '?' + params, success: function (res) {
                            if (res.code === 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('LAY-user-back-manage');
                                layer.close(index); //关闭弹层
                            } else {
                                console.log(res);
                                layer.msg(res.msg, {icon: 5});
                                return false;
                            }
                        }
                    });
                })
            } else if ("approval" === e.event) {
                var params = $.param({'wf_fid': e.data.from_id, 'wf_type': e.data.from_table});
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '审批页面'
                    , content: approval_check + '?' + params
                    , area: ['80%', '80%']
                    , maxmin: true
                    , btn: ['提交', '回退', '会签', '会签提交', '会签回退', '再会签', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            field['submit_to_save'] = 'ok';
                            field['art'] = '';
                            field['sing_st'] = 0;
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url: approval_check,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    },
                    btn2: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            field['submit_to_save'] = 'back';
                            field['art'] = '';
                            field['sing_st'] = 0;
                            $.ajax({
                                url: approval_check,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                        return false;
                    },
                    btn3: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            field['submit_to_save'] = 'sing';
                            field['art'] = '';
                            field['sing_st'] = 0;
                            $.ajax({
                                url: approval_check,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                        return false;
                    }, btn4: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            field['submit_to_save'] = 'sok';
                            field['art'] = '';
                            field['sing_st'] = 1;
                            $.ajax({
                                url: approval_check,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                        return false;
                    }, btn5: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            field['submit_to_save'] = 'sback';
                            field['art'] = '';
                            field['sing_st'] = 1;
                            $.ajax({
                                url: approval_check,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                        return false;
                    }, btn6: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            field['submit_to_save'] = 'ssing';
                            field['art'] = '';
                            field['sing_st'] = 1;
                            $.ajax({
                                url: approval_check,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                        return false;
                    }
                    , success: function (layero, index) {
                        $.ajax({
                            url: "{:url('flow/success_info')}",
                            data: params,
                            type: "post",
                            success: function (res) {
                                if (res == 1) {
                                    $(".layui-layer-btn0").css("display", "none");
                                    $(".layui-layer-btn1").css("display", "none");
                                    $(".layui-layer-btn2").css("display", "none");
                                } else {
                                    $(".layui-layer-btn3").css("display", "none");
                                    $(".layui-layer-btn4").css("display", "none");
                                    $(".layui-layer-btn5").css("display", "none");
                                }
                            }
                        });

                    }
                });
            } else if ("flow_design" === e.event) {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '流程图设计'
                    , content: flowDesign + '?' + param
                    , area: ['80%', '80%']
                    , maxmin: true
                });
            } else if ("check_flow" === e.event) {
                var params = $.param({'wf_fid': e.data.id, 'wf_type': 'vacations'});
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '审批过程'
                    , content: checkFlow + '?' + params
                    , area: ['80%', '80%']
                    , maxmin: true
                });
            }
        });
        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('LAY-user-back-manage', {
                where: field
            });
        });

        $("body").on("click", '.approval', function () {
            var wf_type = $(this).data('type');
            var wf_id = $(this).data('id');
            var params = $.param({'wf_fid': wf_id, 'wf_type': wf_type});
            layer.open({
                type: 2
                , skin: 'layui-layer-molv'
                , title: '审批页面'
                , content: approval_check + '?' + params
                , area: ['80%', '80%']
                , maxmin: true
                , btn: ['提交', '回退', '会签', '会签提交', '会签回退', '再会签', '取消']
                , yes: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-back-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        field['submit_to_save'] = 'ok';
                        field['art'] = '';
                        field['sing_st'] = 0;
                        //提交 Ajax 成功后，静态更新表格中的数据
                        $.ajax({
                            url: approval_check,
                            type: 'post',
                            data: field,
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    window.location.reload();
                                    layer.close(index); //关闭弹层
                                } else {
                                    console.log(res);
                                    layer.msg(res.msg, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                },
                btn2: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-back-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        field['submit_to_save'] = 'back';
                        field['art'] = '';
                        field['sing_st'] = 0;
                        $.ajax({
                            url: approval_check,
                            type: 'post',
                            data: field,
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('LAY-user-back-manage');
                                    layer.close(index); //关闭弹层
                                } else {
                                    console.log(res);
                                    layer.msg(res.msg, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                    return false;
                },
                btn3: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-back-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        field['submit_to_save'] = 'sing';
                        field['art'] = '';
                        field['sing_st'] = 0;
                        $.ajax({
                            url: approval_check,
                            type: 'post',
                            data: field,
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('LAY-user-back-manage');
                                    layer.close(index); //关闭弹层
                                } else {
                                    console.log(res);
                                    layer.msg(res.msg, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                    return false;
                }, btn4: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-back-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        field['submit_to_save'] = 'sok';
                        field['art'] = '';
                        field['sing_st'] = 1;
                        $.ajax({
                            url: approval_check,
                            type: 'post',
                            data: field,
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('LAY-user-back-manage');
                                    layer.close(index); //关闭弹层
                                } else {
                                    console.log(res);
                                    layer.msg(res.msg, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                    return false;
                }, btn5: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-back-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        field['submit_to_save'] = 'sback';
                        field['art'] = '';
                        field['sing_st'] = 1;
                        $.ajax({
                            url: approval_check,
                            type: 'post',
                            data: field,
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('LAY-user-back-manage');
                                    layer.close(index); //关闭弹层
                                } else {
                                    console.log(res);
                                    layer.msg(res.msg, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                    return false;
                }, btn6: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-user-back-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        var field = data.field; //获取提交的字段
                        field['submit_to_save'] = 'ssing';
                        field['art'] = '';
                        field['sing_st'] = 1;
                        $.ajax({
                            url: approval_check,
                            type: 'post',
                            data: field,
                            success: function (res) {
                                if (res.code === 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('LAY-user-back-manage');
                                    layer.close(index); //关闭弹层
                                } else {
                                    console.log(res);
                                    layer.msg(res.msg, {icon: 5});
                                    return false;
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                    return false;
                }
                , success: function (layero, index) {
                    $.ajax({
                        url: "{:url('flow/success_info')}",
                        data: params,
                        type: "post",
                        success: function (res) {
                            if (res == 1) {
                                $(".layui-layer-btn0").css("display", "none");
                                $(".layui-layer-btn1").css("display", "none");
                                $(".layui-layer-btn2").css("display", "none");
                            } else {
                                $(".layui-layer-btn3").css("display", "none");
                                $(".layui-layer-btn4").css("display", "none");
                                $(".layui-layer-btn5").css("display", "none");
                            }
                        }
                    });

                }
            });
        });
        //事件
        var active = {
            batchdel: function () {
                var checkStatus = table.checkStatus('LAY-user-back-manage')
                    , checkData = checkStatus.data; //得到选中的数据
                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }
                var id = ''; //task_id
                for (var i = 0; i < checkData.length; i++) {
                    id += checkData[i].id + ",";
                }
                id = id.substring(0, id.length - 1);
                var ids = $.param({'ids': id});
                layer.confirm('确定删除吗？', function (index) {
                    //执行 Ajax 后重载
                    $.ajax({
                        url: deleteUrl,
                        type: "post",
                        data: ids,
                        success: function (res) {
                            if (res.code === 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('LAY-user-back-manage');
                                layer.close(index); //关闭弹层
                            } else {
                                console.log(res);
                                layer.msg(res.msg, {icon: 5});
                                return false;
                            }
                        }
                    });
                    // table.reload('LAY-user-back-manage');
                    // layer.msg('已删除');
                });
            }
            , add: function () {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '添加'
                    , content: create
                    , area: ['80%', '80%']
                    , maxmin: true
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-back-submit'
                            , submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url: create,
                                type: 'post',
                                data: field,
                                success: function (res) {
                                    if (res.code === 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        table.reload('LAY-user-back-manage');
                                        layer.close(index); //关闭弹层
                                    } else {
                                        console.log(res);
                                        layer.msg(res.msg, {icon: 5});
                                        return false;
                                    }
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
            }, refresh: function () {
                table.reload('LAY-user-back-manage');
            },
            tongbu: function () {
                layer.open({
                    type: 2
                    , skin: 'layui-layer-molv'
                    , title: '同步数据'
                    , content: synchronization
                    , area: ['80%', '80%']
                    , maxmin: true
                })
            },
            export: function () {
                var checkStatus = table.checkStatus('LAY-user-back-manage')
                    , checkData = checkStatus.data; //得到选中的数据

                // if (checkData.length === 0 && district === "") {
                //     return layer.msg('请选择需要导出数据');
                // }
                var id = ''; //task_id
                for (var i = 0; i < checkData.length; i++) {
                    id += checkData[i].id + ",";
                }
                id = id.substring(0, id.length - 1);
                var title = $('#title').val(); //店面名称
                var district = document.getElementById('district').value; //区域
                var businessDistrict = document.getElementById('businessDistrict').value; //商圈
                layer.confirm("确定导出数据吗", function (t) {
                    $.ajax({
                        url: downloadReportExportUrl,
                        type: "post",
                        data: {
                            ids: id,
                            title: title,
                            district: district,
                            businessDistrict: businessDistrict,
                        },
                        beforeSend: function () {
                            layer.close(t);
                            layer.load(2, {
                                shade: [0.6, '#fff'], content: '数据下载中...', success: function (layero) {
                                    layero.find('.layui-layer-content').css({
                                        'padding-top': '6px',
                                        'width': '150px',
                                        'padding-left': '40px'
                                    });
                                    layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                        'width': '150px !important',
                                        'background-position': '2px 0 !important'
                                    });
                                }
                            });
                        },
                        success: function (res) {
                            if (res.code === 400) {
                                layer.msg(res.message, {icon: 5}, function () {
                                    layer.closeAll();
                                });
                                return false;
                            } else {
                                var dataObj = eval("(" + res + ")");
                                if (dataObj.code == 200) {
                                    layer.closeAll();
                                    window.location.href = dataObj.url;
                                } else {
                                    layer.msg("暂无查询到有效数据", {icon: 5});
                                    return false;
                                }
                            }
                        }
                    });
                });
            }
        };
        $('.layui-btn.layuiadmin-btn-admin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });


</script>